from PyQt4  import QtCore, QtGui

class KGraphicsSceneMenu(QtGui.QMenu):
	def __init__(self, scene):
		QtGui.QMenu.__init__(self)

		self.scene=scene
		self.submenulist=[] #maintain all menus

		# define menu operations
		MenusTable=[
			["Time Periods", [["Daily Intervals","Time_1"],
				              ["Weekly Intervals","Time_7"],
				              ["Monthly Intervals","Time_30"],
				              ["Yearly Intervals","Time_365"]]
			 ],
			["Chart Settings",[]
			 ],
			["Studies",[["Add New Study","Study_Add"],
				        ["Configure Existing Study","Study_Config"],
				        ["Remove Existing Study Intervals","Study_Remove"]]
			 ],
			["Tools",[]
			 ],
			["Draw",[]
			 ]
		]
  
		# add Menus
		for each_menu in MenusTable:
			PeriodSubMenu=QtGui.QMenu(each_menu[0],self)
			self.addMenu(PeriodSubMenu)
			m_mapper=QtCore.QSignalMapper(self)
			for each_action in each_menu[1]:            
				#mAction=QtGui.QAction(each_action[0],PeriodSubMenu)
				mAction=QtGui.QAction(each_action[0],PeriodSubMenu)
				m_mapper.setMapping(mAction,each_action[1])
				self.connect(mAction,QtCore.SIGNAL("triggered()"),m_mapper,QtCore.SLOT("map()"))
				PeriodSubMenu.addAction(mAction)
			m_mapper.mapped[QtCore.QString].connect(self.scene.ContextMenuClicked)  

	def ExceuteAction(self,sAction):
		self.scene.ExceuteMenuAction(sAction)


